package com.lightningtrade.domain;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

@ApiModel(description = "用户实体类")
public class SysUser {
    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public List<String> getRole() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            // 假设 role 是字符串：["admin","user"]
            return objectMapper.readValue(role, new TypeReference<List<String>>() {});
        } catch (Exception e) {
            throw new RuntimeException("解析角色字符串失败", e);
        }
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

    public Double getAccount() {
        return account;
    }

    public void setAccount(Double account) {
        this.account = account;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public String getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(String updatedAt) {
        this.updatedAt = updatedAt;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @ApiModelProperty(value = "用户ID", example = "1")
    private Integer uid;

    @ApiModelProperty(value = "用户名", example = "JohnDoe")
    @NotNull(message = "用户名不能为空")
    private String username;

    @ApiModelProperty(value = "密码", example = "password123")
    @NotNull(message = "密码不能为空")
    private String password;

    @ApiModelProperty(value = "用户角色", example = "admin")
    private String role;

    @ApiModelProperty(value = "昵称", example = "John")
    private String nickname;

    @ApiModelProperty(value = "邮箱", example = "johndoe@example.com")
    private String email;

    @ApiModelProperty(value = "手机号", example = "13800000000")
    private String phone;

    @ApiModelProperty(value = "地址", example = "China, Beijing")
    private String address;

    @ApiModelProperty(value = "头像URL", example = "https://example.com/avatar.jpg")
    private String avatarUrl;

    @ApiModelProperty(value = "账户余额", example = "1000.00")
    private Double account;

    @ApiModelProperty(value = "创建时间", example = "2024-01-01T00:00:00")
    private String createdAt;

    @ApiModelProperty(value = "更新时间", example = "2024-01-02T00:00:00")
    private String updatedAt;

    @ApiModelProperty(value = "用户状态", example = "0")
    private Integer status;
}